package plantshop.server;
import java.io.IOException;
import java.io.Serializable;
import java.net.ServerSocket;
import java.util.List;

import plantshop.model.Client;


public class ServerListenThread extends Thread implements Serializable{
	private static final long serialVersionUID = 5621603256983279235L;

	public static final int MAX_PLAYERS = 2;
	
	private ServerSocket serverSocket;

	private List<Client> clients;
	
	public ServerListenThread(ServerSocket serverSocket, List<Client> clients){
		this.serverSocket = serverSocket;
		this.clients = clients;
	}

	@Override
	public void run(){
		while(clients.size() < MAX_PLAYERS){
			try {
				clients.add(new Client(serverSocket.accept()));
			} catch (IOException e) {
				System.err.println("Accept failed. error: " + e);
				System.exit(1);
			}
		}
	}
	
	public List<Client> getClients(){
		return clients;
	}
	
	public boolean isFull()
	{
		System.out.println(clients.size());
		return clients.size() == MAX_PLAYERS;
	}
}
